<template>
  <view class="login-container">
    <view class="form-box">
      <text class="title">登录</text>
      <view class="input-item">
        <input type="text" placeholder="请输入用户名" v-model="username" />
      </view>
      <view class="input-item">
        <input type="password" placeholder="请输入密码" v-model="password" />
      </view>
      <button class="login-btn" @click="handleLogin">登录</button>
      <navigator url="/pages/register/register" class="nav-link">没有账号？去注册</navigator>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    handleLogin() {
      if (!this.username || !this.password) {
        uni.showToast({
          title: '请输入用户名和密码',
          icon: 'none'
        })
        return
      }
      // 模拟登录成功后跳转到主页面
      if (this.username === 'cwx' && this.password === '123456'){
          uni.showLoading({
            title: '登录中...'
          })
          setTimeout(() => {
            uni.hideLoading()
            uni.showToast({
              title: '登录成功'
            })
            // 实际项目中这里跳转到首页
            uni.navigateTo({
              url: "/pages/index/index"
            })
          }, 1000)
        } else {
          uni.showToast({
            title: '密码错误, 请重新输入'
          });
          this.password = '';
          this.isPwdfocus = true;
        }
		}
		}
      }
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f8f8f8;
}
.form-box {
  width: 80%;
  background-color: #fff;
  padding: 30rpx;
  border-radius: 12rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
}
.title {
  display: block;
  text-align: center;
  font-size: 40rpx;
  font-weight: bold;
  margin-bottom: 40rpx;
}
.input-item {
  margin-bottom: 30rpx;
}
.input-item input {
  width: 100%;
  height: 80rpx;
  border: 1rpx solid #ddd;
  border-radius: 6rpx;
  padding: 0 20rpx;
  box-sizing: border-box;
}
.login-btn {
  width: 100%;
  height: 80rpx;
  background-color: #007aff;
  color: #fff;
  border-radius: 6rpx;
  margin-bottom: 20rpx;
}
.nav-link {
  display: block;
  text-align: center;
  font-size: 28rpx;
  color: #007aff;
}
</style>